var utils = require('../../utils/util.js')
Page({
  data:{
    title:"Page productdetail",
    detail:null,
    current_cost:null
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
    console.log(options)
    wx.showToast({
      title: '加载中',
      icon: 'loading',
      duration: 10000
    })
    wx.showNavigationBarLoading()
    var that = this
    wx.request({
      url:'https://www.zhaoyg.cn/index/getinsurancetemplatedetail?id='+options.id,
      data:{},
      method:'GET',
      header:{
        'content-type':'json'
      },
      success:function(res){
        console.log(res)
        wx.setNavigationBarTitle({
          title:res.data.product_name
        })
        that.setData({
          detail:res.data,
          current_cost:res.data.pay_type[0],
        })
        wx.hideNavigationBarLoading()
      }
    })
  },
  bindViewTap:function() {
    var that=this;
    wx.navigateTo({
      url: 'class?id='+that.data.detail.id
    })
  },
  radioChange:function(e){
      console.log(e)
      var that = this
      var index = utils.findElem(that.data.detail.pay_type,'type',e.detail.value)
      that.setData({
              current_cost:that.data.detail.pay_type[index]
            })
  },
  onReady:function(){
    // 页面渲染完成
    wx.hideToast()
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})